/**
 * @author 董一华
 * @since 1.00
 * @version 1.00
 * 
 * 按钮控件
 * 使用说明：
 * jsp中使用范例(最短模式)：<htdz-tag:ButtonTag value="查 询"/>
 *             （最常用）：<htdz-tag:ButtonTag value="查 询" onclick="search()"/>
 * 参数说明：
 * 1. type可以不写，可输入的值为：button,submit,reset。缺省值为button
 * 2. name可以不写
 * 3. id可以不写
 * 4. value必填项：按钮名称
 * 5. onclick可以不写
 * 6. disabled可以不写，可输入的值为：true或false
 * 
 * 修订列表： v1.00 2009-11-12 
 * 			修订人：董一华 
 * 			修订内容：初始版本
 * 
 */

package com.zjht.gmcc.bean.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.zjht.gmcc.bean.util.MyFormat;

public class ButtonTag extends TagSupport {
	private static final long serialVersionUID = 7343418033252888637L;
	private String type;
	private String name;
	private String id;
	private String value;
	private String onclick;
	private boolean disabled;

	public ButtonTag() {
	}

	@SuppressWarnings("static-access")
	public int doStartTag() throws JspException {

		String name = this.name;
		String id = this.id;
		String type = this.type;
		String value = this.value;
		String onclick = this.onclick;
		boolean disabled = this.disabled;

		if (value == null || value.length() == 0) {
			throw new JspException("按钮名称不能为空！");
		}
		if (type == null || type.length() == 0) {
			type = "button";
		}
		StringBuilder html = new StringBuilder();

		try {
			html.append("<input type=\"");
			html.append(type);
			html.append("\" ");
			if (name != null && name.length() > 0) {
				html.append("name=\"");
				html.append(name);
				html.append("\" ");
			}
			if (id != null && id.length() > 0) {
				html.append("id=\"");
				html.append(id);
				html.append("\" ");
			}
			if (onclick != null && onclick.length() > 0) {
				html.append("onclick=\"");
				html.append(onclick);
				html.append("\" ");
			}
			html.append(MyFormat.getButtonClass(disabled, value));
			html.append(" />");
			pageContext.getOut().print(html.toString());
		} catch (Exception e) {
			throw new JspException(e.getMessage());
		}
		html=null;
		return this.SKIP_BODY;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = (disabled != null && "true".equals(disabled.trim().toLowerCase()));
	}
}
